/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package uimigration.Interactions.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import uimigration.Interactions.Behaviour;
import uimigration.Interactions.InteractionsPackage;
import uimigration.Plateform.Device;
import uimigration.mappingmodel.BehaviourType;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Behaviour</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link uimigration.Interactions.impl.BehaviourImpl#getIdBehavior <em>Id Behavior</em>}</li>
 *   <li>{@link uimigration.Interactions.impl.BehaviourImpl#getName <em>Name</em>}</li>
 *   <li>{@link uimigration.Interactions.impl.BehaviourImpl#getComposedBehaviors <em>Composed Behaviors</em>}</li>
 *   <li>{@link uimigration.Interactions.impl.BehaviourImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class BehaviourImpl extends InputImpl implements Behaviour {
	/**
	 * The default value of the '{@link #getIdBehavior() <em>Id Behavior</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIdBehavior()
	 * @generated
	 * @ordered
	 */
	protected static final int ID_BEHAVIOR_EDEFAULT = 0;
	/**
	 * The cached value of the '{@link #getIdBehavior() <em>Id Behavior</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIdBehavior()
	 * @generated
	 * @ordered
	 */
	protected int idBehavior = ID_BEHAVIOR_EDEFAULT;
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;
	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;
	/**
	 * The cached value of the '{@link #getComposedBehaviors() <em>Composed Behaviors</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getComposedBehaviors()
	 * @generated
	 * @ordered
	 */
	protected Behaviour composedBehaviors;
	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final BehaviourType TYPE_EDEFAULT = BehaviourType.RENDER;
	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected BehaviourType type = TYPE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BehaviourImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return InteractionsPackage.Literals.BEHAVIOUR;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getIdBehavior() {
		return idBehavior;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIdBehavior(int newIdBehavior) {
		int oldIdBehavior = idBehavior;
		idBehavior = newIdBehavior;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					InteractionsPackage.BEHAVIOUR__ID_BEHAVIOR, oldIdBehavior,
					idBehavior));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					InteractionsPackage.BEHAVIOUR__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Behaviour getComposedBehaviors() {
		if (composedBehaviors != null && composedBehaviors.eIsProxy()) {
			InternalEObject oldComposedBehaviors = (InternalEObject) composedBehaviors;
			composedBehaviors = (Behaviour) eResolveProxy(oldComposedBehaviors);
			if (composedBehaviors != oldComposedBehaviors) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE,
							InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS,
							oldComposedBehaviors, composedBehaviors));
			}
		}
		return composedBehaviors;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Behaviour basicGetComposedBehaviors() {
		return composedBehaviors;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setComposedBehaviors(Behaviour newComposedBehaviors) {
		Behaviour oldComposedBehaviors = composedBehaviors;
		composedBehaviors = newComposedBehaviors;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS,
					oldComposedBehaviors, composedBehaviors));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BehaviourType getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(BehaviourType newType) {
		BehaviourType oldType = type;
		type = newType == null ? TYPE_EDEFAULT : newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					InteractionsPackage.BEHAVIOUR__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void trigger(Device d) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case InteractionsPackage.BEHAVIOUR__ID_BEHAVIOR:
			return new Integer(getIdBehavior());
		case InteractionsPackage.BEHAVIOUR__NAME:
			return getName();
		case InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS:
			if (resolve)
				return getComposedBehaviors();
			return basicGetComposedBehaviors();
		case InteractionsPackage.BEHAVIOUR__TYPE:
			return getType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case InteractionsPackage.BEHAVIOUR__ID_BEHAVIOR:
			setIdBehavior(((Integer) newValue).intValue());
			return;
		case InteractionsPackage.BEHAVIOUR__NAME:
			setName((String) newValue);
			return;
		case InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS:
			setComposedBehaviors((Behaviour) newValue);
			return;
		case InteractionsPackage.BEHAVIOUR__TYPE:
			setType((BehaviourType) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
		case InteractionsPackage.BEHAVIOUR__ID_BEHAVIOR:
			setIdBehavior(ID_BEHAVIOR_EDEFAULT);
			return;
		case InteractionsPackage.BEHAVIOUR__NAME:
			setName(NAME_EDEFAULT);
			return;
		case InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS:
			setComposedBehaviors((Behaviour) null);
			return;
		case InteractionsPackage.BEHAVIOUR__TYPE:
			setType(TYPE_EDEFAULT);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case InteractionsPackage.BEHAVIOUR__ID_BEHAVIOR:
			return idBehavior != ID_BEHAVIOR_EDEFAULT;
		case InteractionsPackage.BEHAVIOUR__NAME:
			return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT
					.equals(name);
		case InteractionsPackage.BEHAVIOUR__COMPOSED_BEHAVIORS:
			return composedBehaviors != null;
		case InteractionsPackage.BEHAVIOUR__TYPE:
			return type != TYPE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String toString() {
		//if (eIsProxy())
		//	return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		//		result.append(" (idBehavior: ");
		//		result.append(idBehavior);
		//		result.append(", name: ");
		//		result.append(getLongName());
		//		result.append(')');
		result.append(getLongName());
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	private String getLongName() {
		String name = "";
		if (this.getComposedBehaviors() == null)
			name = this.getClass().getClass().getCanonicalName() + "_"
					+ this.getIdBehavior();
		else {
			Behaviour bi = this.getComposedBehaviors();
			while (bi != null) {
				name += "+" + bi.getClass().getClass().getCanonicalName() + "_"
						+ bi.getIdBehavior();
				bi = bi.getComposedBehaviors();
			}
		}
		return name;
	}

} //BehaviourImpl
